<?php

// bkt_del.php
// Michael Baker
// 2010.07.12
//
// Drop a thresholding bracket

session_start();

define("IN_MDM", true);
define("CUR_PAGE_TITLE", "Delete bracket");
define("CUR_FLAG", "bkt.del");

include '../includes/all.php';
include 'inc/header.php';

$id = $_GET[ "id" ];

if ( $_GET[ "confirm" ] )
{
  $dependencies = count( $dbase->get_nodecouples_by_category( $id ) );
  
  if ( $dependencies )
  {
    // bracket has dependencies; don't delete
    $_SESSION[ "MESSAGE" ] = array( 1, "Cannot delete bracket #$id: used by $dependencies segments" );
  }
  else 
  {
    // no dependencies; perform the deletion
    $dbase->delete_thresholding_category( $id );  
    $_SESSION[ "MESSAGE" ] = array( 0, "Bracket #$id deleted" );
  }
  
  // redirect user to bracket list
  header( "Location: bkt_list.php" );
}
else
{
  $_SESSION[ "from" ]        = "bkt_list.php";
  $_SESSION[ "to" ]          = "bkt_del.php?id=$id&confirm=1";
  $_SESSION[ "confirm_msg" ] = "Are you sure you wish to delete this bracket and <strong>all its thresholding data</strong>?";
  
  // redirect user to confirmation page
  header( "Location: confirm.php" );
}

?>